package edu.mis.modules.orderList;

import java.util.Date;
import java.util.List;


import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import edu.mis.model.OrderList;


public class OrderListService {
	
	/**
	 * 添加商品
	 * @param orderList
	 * @return
	 */
	public boolean addOrderList(OrderList orderList){
			return orderList.save();

	}
    /**
     * 修改商品信息
     * @param orderList
     * @return
     */
    public boolean updateOrderList(OrderList orderList){
            return orderList.update();
    }
	

	

	
	/**
	 * 根据ID得到商品
	 * @param id
	 * @return
	 */
	public OrderList findOrderListById(int id) {
		return OrderList.dao.findById(id);
	}
	
	/**
	 * 查询所有商品
	 * @return
	 */
	public List<OrderList> findAll(){
		return OrderList.dao.findAll();
	}
	/**
	 * 查询所有商品及其权限
	 * @return
	 */
	public List<Record> findAllOrderListWithStatus(){
		return OrderList.dao.findAllRecord();
	}
	public List<Record> findAllOrderListWithStatusId(Integer statusId){
		return OrderList.dao.findAllOrderListWithStatusId(statusId);
	}
	public List<Record> findAllOrderListWithCheckin(String checkin){
		return OrderList.dao.findAllOrderListWithCheckin(checkin);
	}
	public List<Record> findCheckinOrderListWithCheckinAndStatus(String checkin, Integer statusId){
		return OrderList.dao.findCheckinOrderListWithCheckinAndStatus(checkin, statusId);
	}
	public List<Record> findAllOrderListWithCheckout(String checkout){
		return OrderList.dao.findAllOrderListWithCheckout(checkout);
	}
	public List<Record> findCheckoutOrderListWithCheckoutAndStatus(String checkout, Integer statusId){
		return OrderList.dao.findCheckoutOrderListWithCheckoutAndStatus(checkout, statusId);
	}
	/**
	 * 查询订单详细
	 * @return
	 */
	public List<Record> findAllOrderDetailsById(int id){
		return OrderList.dao.findAllOrderDetailsWithRoomType(id);
	}
	public List<Record> findAllOrderDetailCustomersById(int id){
		return OrderList.dao.findAllOrderDetailsWithCustomer(id);
	}
	public List<Record> findAllOrderDetailRoomsById(int id){
		return OrderList.dao.findAllOrderDetailsWithRoom(id);
	}

	/**
	 * 订单结账
	 * @param id
	 * @param statusId
	 * @return
	 */
	public boolean checkInOrderList(int id, int statusId) {
		OrderList orderList = findOrderListById(id);
		orderList.setStatusId(statusId);
		return orderList.update();
	}
	/**
	 * 订单结账
	 * @param id
	 * @param statusId
	 * @return
	 */
	public boolean checkOutOrderList(int id, int statusId) {
		OrderList orderList = findOrderListById(id);
		orderList.setStatusId(statusId);
		orderList.setCheckoutTime(new Date());
		return orderList.update();
	}
	/**
	 * 删除商品
	 * @param id
	 * @return
	 */
	public boolean deleteOrderListById(int id) {
		return OrderList.dao.deleteById(id);
	}


	public OrderList findOrderListByDateTime(Date orderTime) {
		return OrderList.dao.findOrderListByDateTime(orderTime);
	}
}
